package com.hibase.core.excel;

import com.hibase.core.excel.context.method.support.HandlerRequestExcelMethodArgumentResolver;
import com.hibase.core.excel.util.ExcelConfigUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter;

import javax.annotation.PostConstruct;
import java.util.ArrayList;
import java.util.List;

/**
 * Hibase-Excel 自动化配置
 *
 * @author <a href="mailto:xiongliyi@hichain.com">Ian Xiong</a>
 * @since 1.4.35-V2
 */
@RequiredArgsConstructor
@Configuration(proxyBeanMethods = false)
public class HibaseResponseExcelAutoConfiguration {

    private final RequestMappingHandlerAdapter requestMappingHandlerAdapter;
    private final ExcelConfigUtil excelConfigUtil;


    /**
     * 注册Excel处理器
     */
    @PostConstruct
    public void setRequestExcelArgumentResolver() {
        List<HandlerMethodArgumentResolver> argumentResolvers = new ArrayList<>();
        HandlerRequestExcelMethodArgumentResolver handlerRequestExcelMethodArgumentResolver = new HandlerRequestExcelMethodArgumentResolver();
        handlerRequestExcelMethodArgumentResolver.setExcelConfigUtil(excelConfigUtil);
        argumentResolvers.add(handlerRequestExcelMethodArgumentResolver);
        argumentResolvers.addAll(requestMappingHandlerAdapter.getArgumentResolvers());
        requestMappingHandlerAdapter.setArgumentResolvers(argumentResolvers);
    }


}
